﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ajayumi.develop.win32.Transport.Client.WinForm.Properties;

namespace ajayumi.develop.win32.Transport.Client.WinForm
{
    /// <summary>
    /// ListenBase.cs 监听基类
    /// Author   : 黄乙冬
    /// Date     : 2011-11-16
    /// </summary>
    internal abstract class ListenBase
    {
        #region Variables

        protected readonly object m_LockObj = null;
        protected System.Threading.Timer m_Timer = null;

        #endregion

        #region Properties

        /// <summary>
        /// 显示异常信息
        /// </summary>
        public Action<string> DisplayMsg { get; set; }

        #endregion


        public ListenBase(Action<string> displayMsg)
        {
            this.m_LockObj = new object();
            this.DisplayMsg = displayMsg;
        }

        protected abstract void ListenTask();

        internal void Start()
        {
            this.Stop();
            //this.m_Timer = new System.Threading.Timer(new TimerCallback(_ => { this.ListenTask(); }),
            //    this,
            //    1000 * Settings.Default.ListenInterval,
            //    1000 * Settings.Default.ListenInterval);
        }

        internal void Stop()
        {
            if (this.m_Timer != null)
            {
                this.m_Timer.Dispose();
                this.m_Timer = null;
            }
        }
    }
}
